package com.software.adapterview.product;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;

import com.software.adapterview.R;
import com.software.adapterview.adapters.ProductAdapter;
import com.software.adapterview.entity.Product;

import java.util.List;

public class ProductActivity extends AppCompatActivity {

    private GridView gv_product;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_product);
        //
        initViews();
        //获取数据
        List<Product> productList = Product.getProductList();
        //创建适配器
        ProductAdapter adapter = new ProductAdapter(R.layout.item_product, productList, this);

        gv_product.setAdapter(adapter);
        gv_product.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            }
        });
    }

    private void initViews() {
        //获取adapterView
        gv_product = findViewById(R.id.gv_product);
    }
}